package org.example.比较;

import java.util.Objects;

public class Main {

    public static void main(String[] args) {
        String c = "hello";
        String  a = new String("hello");
        String  b = new String("hello");
        System.out.println(a == b);  // false
        System.out.println(Objects.equals(a, b)); //true
        System.out.println(a.equals(b)); // true
        System.out.println(b == c);  //false

        System.out.println("======================");

        Integer i1 = new Integer(255);
        Integer i2 = new Integer(255);
        System.out.println(i1 == i2); // false,如果Integer在-128~127之间，返回true,因为有缓存
        System.out.println(Objects.equals(i1, i2)); // true
        System.out.println(i1.equals(i2)); //true
    }
}
